/*
******************
* author: 马丰彦
* date: 2019
* function: 封装axios请求全局遮罩
******************
*/

import {
  Loading
} from 'element-ui'
let loading

function startLoading() {
  loading = Loading.service({
    target: '.main-container',
    lock: true,
    text: '加载中',
    fullscreen: false,
    background: 'rgba(0, 0, 0, 0.7)'
  })
}

function endLoading() {
  loading.close()
}

let needLoadingRequestCount = 0
export function showLoading() {
  if (needLoadingRequestCount === 0) {
    startLoading()
  }
  needLoadingRequestCount++
}

export function tryHideLoading() {
  if (needLoadingRequestCount <= 0) return
  needLoadingRequestCount--
  if (needLoadingRequestCount === 0) {
    endLoading()
  }
}
